<?php



require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;


$connection = new AMQPStreamConnection('192.168.10.10',5672,'admin','admin');
$channel = $connection ->channel();

$ttl_time = 15000;

$channel->exchange_declare('topic_log', 'topic', false, false, false);

list($queue_name, ,) = $channel->queue_declare("", false, false, true, false);
print_r($queue_name);
// $binding_keys = ['quick.orange.rabbit','lazy.orange.elephant','quick.orange.fox','lazy.pink.rabbit'];
$binding_keys = array_slice($argv, 1);
print_r($argv);
if( empty($binding_keys )) {
    file_put_contents('php://stderr', "Usage: $argv[0] [binding_key]\n");
    exit(1);
}
print_r($binding_keys);
foreach($binding_keys as $binding_key) {
    $channel->queue_bind($queue_name, 'topic_log', $binding_key);
}

echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";

$callback = function($msg){
  echo ' [x] ',$msg->delivery_info['routing_key'], ':', $msg->body, "\n";
};

$channel->basic_consume($queue_name, '', false, true, false, false, $callback);

while(count($channel->callbacks)) {
    $channel->wait();
}

$channel->close();
$connection->close();
    


